class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    // 设置检索条件
    SetCriterion(item) {
        item['Limit'] = parseInt($("#page-size").val());
        item['PageIndex'] = parseInt($("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page"));
        item['OrderBy'] = _Instance.orderby;

        item['Begin'] = formatNullInputValue($.trim($("#Begin").val()));
        item['End'] = formatNullInputValue($.trim($("#End").val()));
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    FetchByFilter() {
        this.FetchForPage(1);
    }
    FetchAll() {
        $("#Begin").val("");
        $("#End").val("");
        $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", 1);

        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();

        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            content_01 = '<tr _mash_id="' + result[i].id + '" _mash_depplyment_id="' + result[i].deploymentId + '">';
            content_01 += '<td class="column__action"><span title="删除" class="trash" onclick="_Instance.DoDelete($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            content_01 += '<td class="column__action"><span title="显示流程图" class="edit" onclick="_Instance.ShowDefDiagram($(this));"><i class="fa-all fa-info fa-1"></i></span></td>';
            content_01 += '<td>' + formatNullData(result[i].name) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].resourceName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].diagramResourceName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].key) + '</td>';
            content_01 += '<td style="border-right:none;">' + result[i].version + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
    }
    DoDeploy() {
        showModal(650, 260, "部署流程", parent.basePath + "/workflow/process_def/deploy.html", null, function ($dialog) {
            var _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                //_Instance.FetchAll();
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
            }
        });
    }
    DoDelete($self) {
        let _params = super.GetFilter(this.$pagination.attr("_msh_page"));
        _params['DeploymentId'] = $self.parent().parent().attr("_mash_depplyment_id");
        _params['ResourceName'] = $self.parent().parent().find("td").eq(2).text();
        _params['DeletedBy'] = $("#UserId").val();

        super.DoDelete(_params, function (_this, data) {
            if (data.Success === true) {
                _this.BuildDataTable(data);
            } else {
                _this.EmptyTableContent();
            }
            ShowSuccessMessagePanel("删除成功。");
        });
    }
    ShowDefDiagram($self) {
        showModal(1050, 560, "流程定义图", parent.basePath + "/workflow/process_def/" + $self.parent().parent().attr("_mash_id") + "/diagram.html", null, function ($dialog) {
            let _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                //_Instance.FetchAll();
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
            }
        });
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    $("#page-size").val($.cookie("workflow_process_def_list_pagesize") === undefined ? 15 : $.cookie("workflow_process_def_list_pagesize"));
    // 删除已经保存的检索后的数据列表标识数组
    $.cookie("workflow_process_def_list_result", null);

    _Instance = new MyPage(0, null, flag,
            $("#page-size"),
            $("abbr.page_indicator_block,#wrapper__navbar"),
            "workflow_process_def_list_pagesize",
            "workflow_process_def_list_pageindex",
            "workflow_process_def_list_result",
            "/workflow/process_def/fetchForPage.html",
            "/workflow/process_def/deleteDeployedProcess.html");

    //设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });

    _Instance.OnPageLoad();
}

function onPageResize() {
}
